<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}

if($_POST['sub']!=''){
    
    $ids=$_POST["ids"];
    $position_field=$_POST["posids_id"];
    $_GET["catid"]=intval($_POST["catid"]);
    if(!empty($ids)){
        if(!empty($position_field)){
           
     $clist=explode(",",$position_field);
     while(list($k,$v)=each($ids)){
        if(empty($v)){
            continue;
        }
        reset($clist);        
        while(list($k2,$pid)=each($clist)){
            if(empty($pid)){continue;}
            $prow=$ezhand->select("position_data","id"," tid=".$v." and  posid=$pid");
            if(empty($prow)){
                $newsrow=$ezhand->select("thread","catid,modelid"," id=".$v." ");
            $d=array("tid"=>$v,
            "posid"=>$pid,
            "catid"=>$newsrow["catid"],
            "modelid"=>$newsrow["modelid"]
            );    
            $ezhand->insert("position_data",$d);
                            
                
            }
            
        }
            
         }
     }  
    }    

}


$catid=intval($_GET["catid"]);
if(empty($catid)){
    jump('300','没有选择栏目名称','');
}


$categoryinfo=$ezhand->select("category",'*'," id=".$catid);
if(empty($categoryinfo)){
   jump('300','栏目不存在!',''); 
}
$catename=$categoryinfo["catname"];
$modelid=$categoryinfo["modelid"];
$liststyle=$categoryinfo["liststyle"];


$page = !($_POST['pageNum'])?'1':intval($_POST['pageNum']);
$pagesize= !($_POST['numPerPage'])?'20':intval($_POST['numPerPage']);


if(empty($pagesize)){
    $pagesize=20;
}
$frmnum=($page-1)*$pagesize;
$orderField=trim($_POST["orderField"]);
$orderDirection=trim($_POST["orderDirection"]);
if(empty($orderField)){
    $orderField="t.id";
}
if(empty($orderDirection)){
    $orderDirection="desc";
}
if($orderField<>""){
    $order=" order by $orderField ".$orderDirection;
}else{
    $order=" order by t.listorder desc, t.id desc";
}
$q=trim($_POST['q']);
$where="";
if(!empty($q)){
    $where.=" and t.title like '%$q%'";
}
if($modelid==0){
    $total=$ezhand->count("thread t"," catid=".$catid." ".$where);
    $row=$ezhand->select_all("thread t",'*'," catid=".$catid." ".$where." order by listorder desc, id desc");

    $infocontent=$ezhand->select("pages",'content','catid="'.$catid.'"');
}else{
    $status=$_GET["status"];
    if($status==""){
        $where.=" and status=99";
    }elseif($status=="1"){
        $where.=" and status in (1,2,3)";
    }elseif($status=="14"){
        $where.=" and status=14";
     }elseif($status=="99"){
        $where.=" and status=99";
    }elseif($status=="0"){
        $where.=" and status=0";
    }
    if($modelid==17){
    $total=$ezhand->count("thread t,hr h,school s"," t.id=h.tid and h.schoolid=s.tid and t.catid=".$catid." ".$where);
    $row=$ezhand->select_all("thread t,hr h,school s",'t.*,h.schoolid,h.sex,h.area_district,h.area_province,h.area_city,h.birthday,h.nation,h.polity,h.mainprofession,h.refer,h.internum,h.passoknum,s.title as schoolname',"  t.id=h.tid and h.schoolid=s.tid and t.catid=".$catid." ".$where." ".$order." limit ".$frmnum.",".$pagesize);

    }elseif($modelid==18){          
  
    $total=$ezhand->count("thread t,company c"," t.id=c.tid and t.catid=".$catid." ".$where);
    $row=$ezhand->select_all("thread t,company c",'t.*,c.hrdbnum,c.jobnum,c.internum,c.passoknum,c.username,c.area_province,c.area_city,c.area_district',"  t.id=c.tid and t.catid=".$catid." ".$where." ".$order." limit ".$frmnum.",".$pagesize);

    }elseif($modelid==16){          
  
    $total=$ezhand->count("thread t,school c"," t.id=c.tid and t.catid=".$catid." ".$where);
    $row=$ezhand->select_all("thread t,school c",'t.*,c.hrdbnum,c.internum,c.passoknum,c.contect,c.tel,c.username,c.area_province,c.area_city,c.area_district',"  t.id=c.tid and t.catid=".$catid." ".$where." ".$order." limit ".$frmnum.",".$pagesize);
  
    
    }elseif($modelid==19){    
        $total=$ezhand->count("jobs j,thread t,company c"," j.tid=t.id and j.companyid=c.tid  ".$where);
        $row=$ezhand->select_all("jobs j,thread t,company c",'t.id,t.title,t.updatetime,j.area_province,j.numbers,j.money,j.profession,c.title as company,c.tid'," j.tid=t.id and j.companyid=c.tid ".$where." order by t.updatetime desc");
   
           
    }else{
    $total=$ezhand->count("thread t"," catid=".$catid." ".$where);
    $row=$ezhand->select_all("thread t",'t.*'," catid=".$catid." ".$where." ".$order);
    }
    $statuscount=$ezhand->select_2_field("thread","status,count(*)"," catid=".$catid." group by status");
}

?>